package com.leo.m1803.d11;

import com.leo.common.TreeNode;

/**
 * Created by LEO on 2018/3/11.
 */
public class Offer18 {
    public static boolean isSon(TreeNode a, TreeNode b){
        if (isSame(a, b)){
            return true;
        }else {
            if (isSame(a.left, b)){ return true; }
            if (isSame(a.right, b)){ return true; }
        }
        return false;
    }
    private static boolean isSame(TreeNode a, TreeNode b){
        if (b == null){ return true; }
        if (a == null){ return false; }
        if (a.val == b.val){
            return isSame(a.left, b.left) && isSame(a.right, b.right);
        }else {
            return false;
        }
    }
}
